package com.zhengaz.service.blog.controller.admin;

import com.zhengaz.common.core.constant.Constants;
import com.zhengaz.common.core.entity.R;
import com.zhengaz.common.core.vo.PageVo;
import com.zhengaz.service.blog.dto.BlogArticleDto;
import com.zhengaz.service.blog.dto.BlogArticleQueryDto;
import com.zhengaz.service.blog.service.BlogArticleService;
import com.zhengaz.service.blog.vo.BlogArticleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author zhengzg
 * @create 2023-11-26 14:32
 */
@Api(tags = "文章管理控制器")
@RestController
@RequestMapping(Constants.ADMIN + "/blog-article")
public class AdminBlogArticleController {

    Logger log = LoggerFactory.getLogger(AdminBlogArticleController.class);

    @Resource
    private BlogArticleService blogArticleService;

    @PostMapping("/save")
    @ApiOperation("根据类别id获取文章简介")
    public R<Integer> save(@RequestBody BlogArticleDto dto) {
        return R.ok(blogArticleService.saveBlogArticle(dto));
    }

    @GetMapping("/page")
    @ApiOperation("根据类别id获取文章简介")
    public R<PageVo<List<BlogArticleVo>>> getBlogArticleList(BlogArticleQueryDto dto) {
        return R.ok(blogArticleService.getBlogArticleList(dto));
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id获取文章详情")
    public R<BlogArticleVo> getBlogArticleDetail(@PathVariable("id") Integer id) {
        if (Objects.isNull(id)) return R.fail("抱歉，没有找到该文章~");
        return R.ok(blogArticleService.getBlogArticleDetail(id));
    }

}
